//
// Created by jsjxsy on 2022/6/30.
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void functionA(void) {
  printf("functionA 这是函数A\n");
}

int main(void) {
  char *str = "3.14";
  float val = atof(str);
  printf("字符串值 = %s, 浮点值 = %f\n", str, val);

  char *str2 = "20.30300 This is test";
  char *ptr;
  double ret;
  ret = strtod(str2, &ptr);
  printf("数字（double）是 %lf\n", ret);
  printf("字符串部分是 |%s|", ptr);

  /* 注册终止函数 */
  atexit(functionA);
  printf("启动主程序...\n");
  printf("退出主程序...\n");


  printf("PATH : %s\n", getenv("PATH"));
  printf("HOME : %s\n", getenv("HOME"));
  printf("ROOT : %s\n", getenv("ROOT"));

  char *command="ls -a";
  int res = system(command);
  printf("system return : %d\n", res);

  int len = mblen( "this is my name", sizeof(char));
  printf( "多字节字符 %s 的字节长度：%d\n", "this is my name", len );

  time_t t;
  int n = 5;
  /* 初始化随机数发生器 */
  srand(time(&t));

  /* 输出 0 到 50 之间的 5 个随机数 */
  for(int i = 0 ; i < n ; i++ ) {
    printf("%d\n", rand() % 50);
  }
  return 0;
}
